package com.nathan.mq.integration.vender.redismq.receive;

import com.nathan.mq.integration.constant.MQVenderCS;
import com.nathan.mq.integration.excutor.MqThreadExecutor;
import com.nathan.mq.integration.model.QueueMqModel;
import com.nathan.mq.integration.service.IMQMsgReceiver;
import com.nathan.mq.integration.vender.redismq.RedisMqListener;
import com.nathan.mq.integration.vender.redismq.annotation.RedisQueueListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 业务：
 *
 * @Description:
 * @Author: zhujunjie
 * @Date: 2021/12/9 17:20
 */
@Component
@ConditionalOnProperty(name = MQVenderCS.YML_VENDER_KEY, havingValue = MQVenderCS.REDIS_MQ)
@RedisQueueListener(name = QueueMqModel.MQ_NAME)
@ConditionalOnBean(QueueMqModel.IMQReceiver.class)
public class QueueRedisMQReceiver implements IMQMsgReceiver, RedisMqListener<String> {

    @Autowired
    private QueueMqModel.IMQReceiver mqReceiver;

    /**
     * 接收 【 queue 】 类型的消息
     **/
    @Override
    @Async(MqThreadExecutor.EXECUTOR_INTEGRATION_NOTIFY)
    public void receiveMsg(String msg) {
        System.out.println(Thread.currentThread().getName());
        mqReceiver.receive(QueueMqModel.parse(msg));
    }

}
